<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title></title>
	<!-- <link rel="stylesheet" href="./Home/Bootstrap/Css/bootstrap.min.css" /> -->
	<link href="Public/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
	    <!-- Loading Flat UI -->
	    <link href="Public/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
	    <link href="Public/Admin/Flat/docs/assets/css/demo.css" rel="stylesheet">
	    <link rel="shortcut icon" href="Public/Admin/Flat/img/favicon.ico">
	    <!--上传插件引入-->
			<script type="text/javascript" src="Public/uploadify/jquery-1.8.2.min.js"></script>
		    <script type="text/javascript" src="Public/uploadify/jquery.uploadify.min.js"></script>
		    <link rel="stylesheet" type="text/css" href="Public/uploadify/uploadify.css">
    	<!--载入百度编辑器-->
	    	<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.config.js"></script>
    		<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.all.min.js"> </script>
    		<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
    <!--异步代码-->
    <style type="text/css">
    	body{
    		/*margin-bottom: 60px;*/
    	}
    </style>
	<script type="text/javascript">
		$(function(){
			$('[name=cid]').change (function(){
//				声明tid抓取所选tid的属性
				var tid = $('option:selected').attr('tid');
//				获得隐藏域name  赋值给val类型id
				$('[name=type_tid]').val(tid);
				$.ajax({
					type:"post",  
					url:"<?php echo U('getTypeAttr')?>",
					data:{id : tid},
					dataType:'json',
					success:function(phpData){
						//规格(可选)
						var spec = '';
						//属性（不可选）
						var attr = '';
						$.each(phpData, function(k,v) {    
							//规格
							if(v.attribute == 1){
								spec += '<tr class="info">' +
								'<td>'+v.taname+'</td>' +
								'<td>' +
									'<select name="spec['+v.taid+'][value][]" id=""><option value="">请选择</option>';
										$.each(v.tavalues, function(kk,vv) {    
											 spec += '<option value="'+vv+'">'+vv+'</option>';                                                      
										});
									spec += '</select></td><td>附加价格：<input type="text" name="spec['+v.taid+'][price][]" id="" /></td>' +
										'<td><span class="btn btn-success add-spec">增加规格</span></td></tr>';
							
							}else{//属性
								attr += '<tr class="info">' + 
											'<td>'+v.taname+'</td>' + 
											'<td>' + 
											'<select name="attr['+v.taid+']" id=""><option value="">请选择</option>';
												
												$.each(v.tavalues, function(kk,vv) {    
													 attr += '<option value="'+vv+'">'+vv+'</option>';                                                      
												});
												
								attr += '</select></td></tr>';
							}                                                          
						});
						//插入属性
						$('#attr').html(attr);
						$('#spec').html(spec);
					}
				})	
			})
			//点击添加规格
			$('.add-spec').live('click',function(){
				//找到父级的tr
				var parentsTr = $(this).parents('tr');
				//把父级的tr克隆复制
				var cloneTr = parentsTr.clone();
				cloneTr.find('.add-spec').removeClass('add-spec btn-success').addClass('remove-spec btn-danger').html('删除规格');
				//插入下一行
				parentsTr.after(cloneTr);
			})
			//删除规格
			$('.remove-spec').live('click',function(){
				$(this).parents('tr').remove();
			})
		})
	</script>
</head>
<body>
	<div class="container-fluid">
	<div class="row-fluid">
	<div class="span12">

	<form action="" method='post' >
		<fieldset>
			<legend>添加商品</legend>
			<table class='table table-bordered table-hover' style="border:0;">
				<thead>
					<tr>
						<th colspan="2" class="btn btn-primary">基本信息</th>
					</tr>
				</thead>
				<tbody>
					<tr class="">
						<td class="">所属分类</td>
						<td>
	                        <select name="cid">
								<option value="0">-请选择-</option>
								<?php foreach ($cadata as $v){?>
									<option value="<?php echo $v['cid']?>" tid="<?php echo $v['type_tid']?>"><?php echo $v['_name']?></option>
								<?php }?>
							</select>
						</td>
					</tr>
					<tr class="">
						<td>所属品牌</td>
						<td>
							<select name="bid">
								<option value="0">-请选择-</option>
								<?php foreach ($brdata as $v){?>
									<option value="<?php echo $v['bid']?>"><?php echo $v['bname']?></option>
								<?php }?>
							</select>
						</td>
					</tr>
					<tr class="">
						<td>商品名称</td>
						<td>
							<input type="text" name='cmname'/>
						</td>
					</tr>
					<tr class="">
						<td>商品代码</td>
						<td>
							<input type="text" name='cmnb'/>
						</td>
					</tr>
					<tr class="">
						<td>单位</td>
						<td>
							<input type="text" name='cmunit' value="件"/>
						</td>
					</tr>
					<tr class="">
						<td>市价场</td>
						<td>
							<input type="text" name='mktprice'/>
						</td>
					</tr>
					<tr class="">
						<td>商城价</td>
						<td>
							<input type="text" name='sptprice'/>
						</td>
					</tr>
					<tr class="">
						<td>总库存</td>
						<td>
							<input type="text" name='stocks'/>
						</td>
					</tr>
					<tr class="">
						<td>点击次数</td>
						<td>
							<input type="text" name='click'/>
						</td>
					</tr>
				</tbody>
			</table>

			<p class="btn btn-primary">商品属性</p>
			<table class="table table-bordered table-hover" id='attr' class="">
				
			</table>
			<p class="btn btn-primary">商品规格</p>
			<table class="table table-bordered table-hover" id='spec'>
				
			</table>

			<table class='table table-bordered' style="border:0;">
				<tr>
					<th colspan="3" class="btn btn-primary">列表图</th>
				</tr>
				<tr class="">
					<td>上传图片</td>
					<td>
						<div lab="upload">
						    <input id="f1" type="file" multiple="true" >
						    <span>类型: *.jpg,*.png 大小: 2000KB 数量: 1</span>
						    <script type="text/javascript">
						        $(function() {
						            $('#f1').uploadify({
						                'formData'     : {//POST数据
						                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
						                },
						                'fileTypeDesc' : '上传文件',//上传描述
						                'fileTypeExts' : '*.jpg;*.png',
						                'swf'      : '<?php echo __PUBLIC__?>/uploadify/uploadify.swf',
						                'uploader' : "<?php echo U('upload')?>",
						                'buttonText':'选择文件',
						                'fileSizeLimit' : '2000KB',
						                'uploadLimit' : 1,//上传文件数
						                'width':65,
						                'height':25,
						                'successTimeout':10,//等待服务器响应时间
						                'removeTimeout' : 0.2,//成功显示时间
						                'onUploadSuccess' : function(file, data, response) {
						                    //转为json
						                    data=$.parseJSON(data);
						                    //获得图片地址
						                    var imageUrl = data.url;
						                    var li="<li style='list-style: none;'><img style='width: 80px;height: 70px; display: block;float: left;padding-right: 10px;' src='"+imageUrl+"'/><input type='hidden' name='thumb1' value='"+data.path+"'/></li>";
						                    $("#upload ul").prepend(li);
						                }
						            });
						        });
						    </script>
						</div>
					<td id='upload' style="width: 100px;height: 40px; padding: 0px;"><ul></ul></td>
				</tr>
			</table>

			<table class='table table-bordered' style="border:0;">
				<tr>
					<th colspan="3" class="btn btn-primary">商品图册</th>
				</tr>
				<tr class="">
					<td>上传图片</td>
					<td>
						<div lab="uploadFile">
						    <input id="f" type="file" multiple="true">
						    <span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
						    <script type="text/javascript">
						        $(function() {
						            $('#f').uploadify({
						                'formData'     : {//POST数据
						                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
						                },
						                'fileTypeDesc' : '上传文件',//上传描述
						                'fileTypeExts' : '*.jpg;*.png',
						                'swf'      : '<?php echo __PUBLIC__?>/uploadify/uploadify.swf',
						                'uploader' : "<?php echo U('upload')?>",
						                'buttonText':'选择文件',
						                'fileSizeLimit' : '2000KB',
						                'uploadLimit' : 10,//上传文件数
						                'width':65,
						                'height':25,
						                'successTimeout':10,//等待服务器响应时间
						                'removeTimeout' : 0.2,//成功显示时间
						                'onUploadSuccess' : function(file, data, response) {
						                    //转为json
						                    data=$.parseJSON(data);
						                    //获得图片地址
						                    var imageUrl = data.url;
						                    var li="<li style='list-style: none;'><img style='width: 80px;height: 70px; display: block;float: left;padding-right: 10px;' src='"+imageUrl+"'/><input type='hidden' name='thumb2[]' value='"+data.path+"'/></li>";
						                    $("#uploadList ul").prepend(li);
						                }
						            });
						        });
						    </script>
						</div>
					<td id='uploadList' style="width: 600px;height: 40px;"><ul></ul></td>
				</tr>
			</table>
			<!--商品详情点击显示消失-->
			<script>
				$(function() {
					$("#hide").click(function() {
						if ($("#pp").css("display") == "none"){
							$("#pp").show();
						} else {
							$("#pp").hide();
						}
					});
				});
		    </script>

			<table class='table'>
				<tr class="next_show" id='hide'>
					<th class="btn btn-primary">商品详细</th>
				</tr>
				<!--调用百度编辑器-->
				<tr style="display: none;" id="pp">
					<script id="editor" type="text/plain" style="width:100%;height:500px;" name="aboutarticles"></script>
				    <script>
				        var ue = UE.getEditor('editor');
				    </script>
			   </tr>
			    </div>
			</table>
            <script>
				$(function() {
					$("#ppp").click(function() {
						if ($("#pppp").css("display") == "none"){
							$("#pppp").show();
						} else {
							$("#pppp").hide();
						}
					});
				});
		    </script>
			<table class='table'>
				<tr class="next_show" id="ppp">
					<th class="btn btn-primary">售后服务</th>
				</tr>
				<tr id="pppp" style="display: none;">
				<!--调用百度编辑器-->
					<script id="editor1" type="text/plain" style="width:100%;height:500px;" name="service"></script>
				    <script>
				        var ue = UE.getEditor('editor1');
				    </script>
			    </tr>
			</table>
			<input type="hidden" name="type_tid"  value="" />
			<input type="submit" value="确认添加" class="btn btn-primary btn-block" />
		</fieldset>
	</form>

	</div>
	</div>
	</div>
</body>
</html>